package com.isay.app.honey.ui.cash.history;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.isay.app.honey.R;
import com.isay.frameworklib.utils.ClickUtils;
import java.util.ArrayList;
import java.util.List;


/**
 * 智批改recycler adapter
 * <p>
 * Created by cywu4 on 2017/3/13.
 */
public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHolder> implements View.OnClickListener {

    private Context mContext;
    private ArrayList<HistoryItemInfo> mData = new ArrayList<>();


    public HistoryAdapter(Context context) {
        mContext = context;
    }


    public void addData(boolean refresh, List<HistoryItemInfo> data) {
        if (refresh) {
            mData.clear();
        }
        if (data != null) {
            mData.addAll(data);
        }
    }


    @Override
    public int getItemCount() {
        return mData.size();
    }


    @Override
    public long getItemId(int i) {
        return 0;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hisroty_cash, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HistoryItemInfo info = mData.get(position);
        holder.tvMoney.setText(info.getMoney() + "");
        holder.tvTime.setText(info.getTime());
        holder.tvState.setText(info.getState());

    }


    @Override
    public void onClick(View v) {
        if (ClickUtils.isFastClick()) {
            return;
        }
    }


    protected class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tvMoney;
        private TextView tvTime;
        private TextView tvState;

        public ViewHolder(View itemView) {
            super(itemView);
            tvMoney = itemView.findViewById(R.id.tv_money);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvState = itemView.findViewById(R.id.tv_state);
        }
    }

}
